v<template>
  <div class="mnt-dialog form-container">
    <el-form ref="form" :model="formModel" label-width="160px" :rules="rules">
      <el-row style="text-align: center">
        <el-col :span="12">
          <el-form-item label="优先级:" prop="priorityDataKey">
            <hey-select v-model="formModel.priorityDataKey" :clearable="false" clcd="key_priority_type" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="排序规则:" prop="collationDataKey">
            <hey-select v-model="formModel.collationDataKey" clearable="false" clcd="key_rank_type" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="阈值最小值:" prop="limitMin">
            <el-input v-model="formModel.limitMin" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="阈值最大值:" prop="limitMax">
            <el-input v-model="formModel.limitMax" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="启动:" prop="status">
            <hey-select v-model="formModel.status" :clearable="false" clcd="is_effective_cd" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-row class="submit-area">
      <el-col :span="24">
        <el-button @click="closeDialog">取消</el-button>
        <el-button type="primary" @click="handleSubmit()">确定</el-button>
      </el-col>
    </el-row>
  </div>
</template>

<script>

export default {
  name: 'TmBasSortRuleMnt',
  props: ['pageType', 'editData'],
  data() {
    return {
      formModel: {
        sortRuleId: '',
        priorityDataKey: '',
        collationDataKey: '',
        limitMin: '',
        limitMax: '',
        status: '1',
        sortRuleType: 'ZZ'
      },
      rules: {}
    }
  },
  computed: {},
  mounted() {
    this.init()
  },
  methods: {
    init() {
      this.$form = this.$refs.form
      const { pageType, editData, formModel } = this
      if (pageType !== 'add') {
        this.assignData(editData, formModel)
        this.disabledNo = true
      }
      this.initRules()
    },
    initRules() {
      const REQUIRED_MSG = this.CONST.REQUIRED_MSG
      this.rules = {
        priorityDataKey: [{ required: true, message: REQUIRED_MSG, trigger: ['change', 'blur'] }],
        collationDataKey: [{ required: true, message: REQUIRED_MSG, trigger: ['change', 'blur'] }],

        // productTypeDataKey: [{required: true, message: REQUIRED_MSG, trigger: ['change', 'blur']}],
        status: [{ required: true, message: REQUIRED_MSG, trigger: ['change', 'blur'] }]
      }
      this.$nextTick(_ => {
        this.$form.clearValidate()
      })
    },
    handleSubmit() {
      this.$refs.form.validate(valid => {
        if (valid) {
          if (this.formModel.sortRuleId !== '') {
            const tip = '修改成功！'
            const url = '/sortRule/updateSortRule'
            this.post(url, this.formModel).then(res => {
              this.$info(tip, () => {
                this.$emit('mntSuc', res)
                this.closeDialog()
              })
            })
          } else {
            const url = '/sortRule/saveSortRule'
            this.post(url, this.formModel).then(res => {
              const tip = '新增成功！'
              this.$info(tip, () => {
                this.$emit('mntSuc', res)
                this.closeDialog()
              })
            })
          }
        }
      })
    },
    closeDialog() {
      this.$parent.$emit('update:visible', false)
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
